package com.baige.common.core;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * api Controller 基类  主要是来获取请求头数据
 * @author wulg
 * @date 2018/12/12.
 */
public class BaseApiController
{
    private static final String SOURCE="source";
    private static final String APP_VERSION="appVersion";
    private static final String USER_ID="userId";
    private static final String TOKEN="token";
    private static final String SYSTEM="system";
    private static final String APP_BUILD_VERSION="appBuildVersion";
    private static final String DEBUG_MODE="debugMode";
    private static final String CHECK_CODE="checkCode";
    private static final String TIMESTAMP="timeStamp";

    public String getSource() {
        return getServletRequest().getHeader(SOURCE);
    }

    public String getAppVersion() {
        return getServletRequest().getHeader(APP_VERSION);
    }

    public String getUserId() {
        return getServletRequest().getHeader(USER_ID);
    }

    public String getToken() {
        return getServletRequest().getHeader(TOKEN);
    }

    public String getSystem() {
        return getServletRequest().getHeader(SYSTEM);
    }

    public String getAppBuildVersion() {
        return getServletRequest().getHeader(APP_BUILD_VERSION);
    }

    public String getDebugMode() {
        return getServletRequest().getHeader(DEBUG_MODE);
    }

    public String getCheckCode() {
        return getServletRequest().getHeader(CHECK_CODE);
    }

    public String getTimeStamp() {
        return getServletRequest().getHeader(TIMESTAMP);
    }

    private HttpServletRequest getServletRequest() {
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    }

}
